package J1202_morning;

import java.util.LinkedList;
import java.util.ListIterator;

public class Main {
    public static void main(String[] args) {
        //遍历的几种方式
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        //直接打印
        System.out.println(list);
        System.out.println("_________");
        //for循环打印
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("_________");
        //foreach 打印
        for (Integer x: list) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("_________");
        //迭代器正向打印
        ListIterator<Integer> it1 = list.listIterator();
        while(it1.hasNext()) {
            System.out.print(it1.next()+" ");
        }
        System.out.println();
        System.out.println("_________");
        //迭代器反向打印
        ListIterator<Integer> it2 = list.listIterator(list.size());
        while (it2.hasPrevious()) {
            System.out.print(it2.previous()+" ");
        }
        System.out.println();
    }
}
